Date function rule examples

Date function rule examples

Date functions are used to perform a number of common calculations which frequently appear in rules.

Be sure to use the exact syntax for these functions including spacing and parentheses as specified below. Date and number inputs may be either constant values or variables.

Note that in date calculations attempting to exceed the allowable date range with a date too far in the past or future will lead to the Earliest or Latest value as appropriate.

Rule examples

Function Example rule Inputs

Outputs

Further information
CurrentDate

today = the current date

the date of the investigation = CurrentDate()

today's date: 2005-04-15

today's date: 2009-08-31

today = 2005-04-15

the date of the investigation = 2009-08-31

Get today's date
Date

the date of effect =Date("2012-01-01")

2012-01-01 the date of effect = 2012-01-01 Convert a text string into a number or date
MakeDate

the calculation date =MakeDate(2006, 10, 19)

yyyy: 2006; mm: 10; dd: 19

the calculation date = 2006-10-19 Get a date formed from a specified year, month and day
ExtractDay

the day of expiry = ExtractDay(the use-by date on the packet)

the use-by date on the packet: 2008-06-12 the day of expiry = 12 Get the day component of an input date
ExtractMonth

the month of expiry = ExtractMonth(the use-by date on the packet)

the use-by date on the packet: 2007-04-16 the month of expiry = 04 Get the month component of an input date
ExtractYear

the year of expiry = ExtractYear(the use-by date on the packet)

the use-by date on the packet: 2009-02-21 the year of expiry = 2009 Get the year component of an input date
NextDayOfTheWeek

next Monday = NextDayOfTheWeek(the current date,"Monday")

next Tuesday = the next Tuesday on or after the current date

last Thursday = the Thursday on or before the current date

the current date: 2009-08-09

next Monday = 10 August 2009

next Tuesday = 11 August 2009

last Thursday = 6 August 2009

Get the date of the next or previous specified day
AddDays

the date that the library book must be returned by = AddDays(the date of loan,21)

the date that the library book must be returned by = the date 21 days after the date of loan

the closing date for the entry = AddDays(the date of the show,-10)

the date of loan: 2006-01-04

 

the date of the show: 2007-05-15

the date that the library book must be returned by = 25

 

the closing date for the entry = 2007-05-05

Add or subtract a specified number of days to an input date
AddWeeks

the date that the event finishes = AddWeeks(the date that the event begins,the number of weeks in the event)

the date that the event finishes = the date the number of weeks in the event weeks after the date that the event begins

the start date of the 5 week promotion = AddWeeks(the end date of the promotion,-5)

the start date of the 5 week promotion = the date 5 weeks before the end date of the promotion

the date that the event begins: 2001-08-13

the number of weeks in the event: 12

 

the end date of the promotion: 2008-12-24

the date that the event finishes = 2001-11-05

 

the start date of the 5 week promotion = 2008-11-19

Add or subtract a specified number of weeks to an input date
AddMonths

the date that the player can return from suspension = AddMonths(the date of the suspension,3)

the date that the player can return from suspension = the date 3 months after the date of the suspension

the start date of the player's 12 month contract = AddWeeks(the end date of the player's contract,-12)

the start date of the player's 12 month contract = the date 12 months before the end date of the player's contract

the date of the suspension: 2005-12-12

 

the end date of the player's contract: 2006-06-30

the date that the player can return from suspension = 2006-03-12

 

the start date of the player's 12 month contract = 2005-06-30

Add or subtract a specified number of months to an input date
AddYears

the date of the trial = AddYears(the date of the crime,3)

the date of the trial = the date 3 years after the date of the crime

the date that the prison sentence starts = AddYears(the date that the prison sentence ends,-20)

the date that the prison sentence starts = the date 20 years before the date that the prison sentence ends

the date of the crime: 2002-01-01

 

the date that the prison sentence ends: 1980-03-16

the date of the trial = 2005-01-01

 

the date that the prison sentence starts = 1960-03-16

Add or subtract a specified number of years to an input date
YearStart

the start of the first relevant year = YearStart(2009-09-09)

the start of the second relevant year = the first day of the year in which the date of the grand occasion falls

the date of the grand occasion: 2007-09-09

the start of the first relevant year = 2009-01-01

the start of the second relevant year = 2007-01-01

Find the first date in the year
YearEnd

the end of the relevant year = YearEnd(the relevant date)

the end of the relevant year = the last day of the year in which the relevant date falls

the relevant date: 2005-10-15 the end of the relevant year = 2005-12-31 Find the last date in the year
NextDate

the end of the Australian tax year = NextDate(the test date, 30, 6)

the test date: 2005-07-02

the end of the Australian tax year = 2006-06-30

Find the next instance of the given day/month
UKTaxYearDates

the date of effect = the next UK tax year end date on or after the test date

the assessment date = the previous UK tax year start date on or before the test date

the test date: 2003-09-21

the date of effect = 2004-04-05

 

the assessment date = 2003-04-06

Find the start or the end date for the previous or next UK tax year
WeekdayCount

the number of working days until my holiday = WeekdayCount(2007-12-03, 2007-12-13)

the number of business days in the specified period = the number of weekdays (inclusive) between 2007-10-15 and 2007-10-31

date1: 2007-12-03; date2: 2007-12-13

date1: 2007-10-15; date2: 2007-10-31

the number of working days until my holiday = 8

the number of business days in the specified period = 12

Count the number of weekdays between two dates
DayDifference

the number of days in the assessment period = DayDifference(2006-10-01,2006-10-14)

date1: 2006-10-01

date2: 2006-10-14

the number of days in the assessment period = 13 Count the number of whole days between two dates
DayDifferenceInclusive

the number of days in the assessment period = DayDifferenceInclusive(2006-10-01,2006-10-14)

date1: 2006-10-01

date2: 2006-10-14

the number of days in the assessment period = 14
DayDifferenceExclusive

the number of days in the assessment period = DayDifferenceExclusive(2006-10-01,2006-10-14)

date1: 2006-10-01

date2: 2006-10-14

the number of days in the assessment period = 12
WeekDifference

the number of weeks until Christmas = WeekDifference(the current date,2011-12-25)

the current date: 2011-11-25

the number of weeks remaining = 4 Count the number of whole weeks between two dates
WeekDifferenceInclusive

the number of weeks until Christmas = WeekDifferenceInclusive(the current date,2011-12-25)

the current date: 2011-11-25 the number of weeks remaining = 5
WeekDifferenceExclusive

the number of weeks until Christmas = WeekDifferenceExclusive(the current date,2011-12-25)

the current date: 2011-11-25 the number of weeks remaining = 3
MonthDifference

the number of months remaining in the phone contract = MonthDifference(the current date,the expiry date of the contract)

the current date: 2011-11-28

the expiry date of the contract: 2013-03-24

the number of months remaining = 15 Count the number of whole months between two dates
MonthDifferenceInclusive

the number of months remaining in the phone contract = MonthDifferenceInclusive(the current date,the expiry date of the contract)

the current date: 2011-11-28

the expiry date of the contract: 2013-03-24

the number of months remaining = 16
MonthDifferenceExclusive

the number of months remaining in the phone contract = MonthDifferenceExclusive(the current date,the expiry date of the contract)

the current date: 2011-11-28

the expiry date of the contract: 2013-03-24

the number of months remaining = 14
YearDifference


the age of the tree in years = YearDifference(the date the tree was planted, the date the tree was assessed)

the age of the tree in years = the number of years between the date the tree was planted and the date the tree was assessed

the date the tree was planted: 2000-03-12

the date the tree was assessed: 2003-12-12

the age of the tree in years = 3 Count the number of whole years between two dates
YearDifferenceInclusive


the age of the tree in years = YearDifferenceInclusive(the date the tree was planted, the date the tree was assessed)

the age of the tree in years = the number of years (inclusive) between the date the tree was planted and the date the tree was assessed

the date the tree was planted: 2000-03-12

the date the tree was assessed: 2003-12-12

the age of the tree in years = 4
YearDifferenceExclusive


the age of the tree in years = YearDifferenceExclusive(the date the tree was planted, the date the tree was assessed)

the age of the tree in years = the number of years (exclusive) between the date the tree was planted and the date the tree was assessed

the date the tree was planted: 2000-03-12

the date the tree was assessed: 2003-12-12

the age of the tree in years = 2

 

TIP: The localized syntax for these functions may be viewed:

 

See also: